import { defineStore } from 'pinia'

export const useStore  = defineStore('user', {
  state: () => {
    return {
      // 获取本地状态
      userinfo: null,
      error: null,
      count: 0
    }
  },

  getters: {
    doubleCount(state) {
      return this.userinfo = state
    },
  },


  actions: {
    async restoreFromLocalStorage() {
      try {
        const storedUser = localStorage.getItem('loginData')
        if (storedUser) {
          this.userinfo = JSON.parse(storedUser);
        }
      } catch (error) {
        // 处理获取 localStorage 失败的情况
        this.error = error.message;
      }
    }
  }
})